package com.yuwei.goods_detail

import com.yuwei.common.mvi.BaseViewModel
import com.yuwei.database.RoomDBUtils.getGoodsDao
import com.yuwei.database.RoomDBUtils.getOrderDao
import kotlinx.coroutines.flow.flow

class GoodsDetailViewModel: BaseViewModel<GoodsDetailApiService, GoodsDetailIntent>() {
    override fun handleIntent(intent: GoodsDetailIntent) {
        when(intent){
            is GoodsDetailIntent.insertGoods ->{
                roomRequest({getGoodsDao().insert(intent.goodsEntityItem)},"insertGoods")
            }
            is GoodsDetailIntent.goodsAddCar ->{
                httpRequest(apiService.goodsAddCar(intent.goodsCarBody),"addCar")
            }
            is GoodsDetailIntent.insertOrder ->{
                roomRequest({getOrderDao().insertOrder(intent.orderEntity)},"insertOrder")
            }
            is GoodsDetailIntent.getComment ->{
                httpRequest(apiService.getComment(intent.datatype,intent.itemid),"getComment")
            }
        }
    }
}